using UnityEngine;
using System.Collections;

public class ProtectedObject : MonoBehaviour {
	public PObject_data Data;
	// Use this for initialization
	void Start () {
		
		try
		{
			Data = new PObject_data();
			Data.SetData( GameObject.Find("GameData").GetComponent<game_data>() );

		}
		catch
		{
			
		}
		
		
	}
	void Update()
	{
		if( Data.Protected_Residual_HP < Data.Protected_Object_MaxHP)
		{
			Data.Protected_Residual_HP += Data.Protected_Object_HP_Regeneration * Time.deltaTime;
			GameManager.getInstance().HP_Bar.transform.localScale 
			=new Vector3( ((485 * Data.Protected_Residual_HP) / Data.Protected_Object_MaxHP),
							20.0f,
							0.0f);
		}
		else if (Data.Protected_Residual_HP > Data.Protected_Object_MaxHP )
		{
			Data.Protected_Residual_HP = Data.Protected_Object_MaxHP;
		}
	}
	public bool DamagedProtect(float _damage)
	{
		Data.Protected_Residual_HP -= (_damage - Data.Protected_Object_Defense);
		if ( Data.Protected_Residual_HP < 0 )
			Data.Protected_Residual_HP = 1;
		GameManager.getInstance().HP_Bar.transform.localScale 
			=new Vector3( ((485 * Data.Protected_Residual_HP) / Data.Protected_Object_MaxHP),
							20.0f,
							0.0f);
		
		return true;
		
	}
	public bool IsGameOver()
	{
		if( Data.Protected_Residual_HP <= 1 )
			return true;
		return false;
	}
	
}
